﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BitCoinSharp;
using System.Web;
using System.Web.Script.Serialization;
using Taype.Trading.BTC.Utilities;

namespace Taype.Trading.BTC.MtGoxAPIClient.JSONObjects
{
    class MtGoxBTCAddress
    {
        /// <summary>
        /// Parse JSON data returned by the 0/btcAddress.php method
        /// </summary>
        /// <param name="jsonDataStr">JSON data returned by the 0/btcAddress.php method</param>
        /// <returns></returns>
        public static Address getObjects(string jsonDataStr)
        {
            string json = jsonDataStr;
            var serializer = new JavaScriptSerializer();
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            dynamic obj = serializer.Deserialize(json, typeof(object));
            try
            {
                Address newAddr = new Address(new NetworkParameters(), obj.addr);
                return newAddr;
            }
            catch (Exception ex)
            {
                return null;
            }

        }
    }
}
